﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ServiceModel;
using MOMKeLABS.ServiceReference;

namespace MOMKeLABS.Security
{
    public class Authentication
    {


        /// <summary>
        /// Connect to the lab service
        /// </summary>
        /// <returns></returns>
        public static ServiceClient Connect()
        {
            string serviceUri = "";

            if (System.Windows.Browser.HtmlPage.Document.DocumentUri.Host.Contains(Constants.ServiceConstants.LOCAL_SERVER_NAME))
            {
                serviceUri = Constants.ServiceConstants.SERVICE_URL_DEV;
            }
            else if (System.Windows.Browser.HtmlPage.Document.DocumentUri.Host.Contains(Constants.ServiceConstants.LIVE_SERVER_NAME))
            {
                serviceUri = Constants.ServiceConstants.SERVICE_URL_LIVE;
            }
            else
            {
                // don't know what server its running on so die.
                throw new Exception("Can't find service to connect to");
            }

            BasicHttpBinding binding = new BasicHttpBinding();
            binding.MaxBufferSize = Constants.ServiceConstants.SERVICE_MAX_BUFFER_SIZE;
            binding.MaxReceivedMessageSize = Constants.ServiceConstants.SERVICE_MAX_RECEIVE_BUFFER_SIZE;

            return new ServiceClient(binding, new System.ServiceModel.EndpointAddress(serviceUri));
        }
    }
}
